#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "fifo.h"
#include "mutex.h"
#include "rbuf.h"
#include "log.h"


int main()
{
#ifdef FIFO
	fifo_t *fifo = fifo_new(1024, 2);
	
	unsigned char str1[] = "12345";
	unsigned char str2[] = "67890";
	unsigned char str3[] = "abcde";
	unsigned char str4[] = "fghij";
	unsigned char buf[128] = {0};
	int type;
	int ret = -1;
	unsigned int len = sizeof(buf) - 1;
	
	fifo_tlv_write_lock(fifo, 1, str1, (unsigned int)strlen(str1));
	fifo_tlv_write_lock(fifo, 2, str3, (unsigned int)strlen(str1));
	fifo_tlv_write_lock(fifo, 2, str4, (unsigned int)strlen(str1));
	fifo_tlv_write_lock(fifo, 1, str2, (unsigned int)strlen(str1));
	
	while (1) {
		memset(buf, 0, sizeof(buf));
		ret = fifo_tlv_read(fifo, &type, buf, &len);
		if (ret == 0) {
			printf("type:%d len:%d buff:%s\n", type, len, buf);
		}
		sleep(1);
	}

	fifo_free(fifo);
#endif

#ifdef RBUF
	char testBuffer[1024] = {0};
	char str1[] = "123456";
	char str2[] = "789abc";
	char str3[] = "abcdef";
	char str4[] = "111111";
	char buf[128];
	rbuf_init(testBuffer, sizeof(testBuffer));
	
	rbuf_push(testBuffer, str1, strlen(str1));
	rbuf_push(testBuffer, str2, strlen(str2));
	rbuf_push(testBuffer, str3, strlen(str3));
	rbuf_push(testBuffer, str4, strlen(str4));

	int ret;
	while (1) {
		memset(buf, 0 , sizeof(buf));
		ret = rbuf_pop(testBuffer, buf, 6);
		if (ret == 0) {
			printf("rbuf pop:%s\n", buf);
		}
		sleep(1);
	}
#endif

#ifdef CBUF
	
#endif
	FILE *fp = fopen("./test.log", "a+");
	if (fp == NULL)
		return -1;
	
	log_add_fp(fp, 1);
	log_debug("wdnmd");
	log_debug("123435453245435345");
	fclose(fp);

	return 0;
}
